package com.apes.fn.business.insurance.modle;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.hr.base.model.WorkPost;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Branch;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.frame.model.Store;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @program: apes-server
 * @description e保养报表实体
 * @author: czs
 * @create: 2021-08-18 16:55
 **/
@Setter
@Getter
@Entity
@SelectBeforeUpdate
@EntityListeners(DefaultPersistListener.class)
@Table(name = InsuranceDiscountsReport.CONST_TABLE_NAME)
@DynamicInsert
@DynamicUpdate
public class InsuranceDiscountsReport extends Model {
    public static final String CONST_TABLE_NAME = "e_discount_report";
    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "e服务报表", padding = 12)
    @Comment("e服务报表")
    private String id;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "statistic_Date")
    @Comment("统计日期")
    private Date statisticDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "salesman", referencedColumnName = "id")
    @Comment("业务员")
    private PartyRole salesman;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "post_id", referencedColumnName = "id")
    @Comment("岗位")
    private WorkPost post; //岗位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "branch_id", referencedColumnName = "id")
    private Branch branch; //工作部门-行政部门

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "operation", referencedColumnName = "id")
    @Comment("运营模式编码")
    private Enumeration operation; //运营模式

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id",referencedColumnName = "id")
    @Comment("门店")
    private Dept dept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "store_id", referencedColumnName="id")
    private Store store; //门店信息

    @Column(name = "qty_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("当天销售单数")
    private double qtyOrder = 0;

    @Column(name = "price_date", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("当天销售金额")
    private double priceDate = 0;

    @Column(name = "maintain_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("e保养订单")
    private double maintainOrder = 0;

    @Column(name = "maintain_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("e保养金额")
    private double maintainPrice = 0;

    @Column(name = "tire_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("e轮胎订单")
    private double tireOrder = 0;

    @Column(name = "tire_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("e轮胎金额")
    private double tirePrice = 0;

    @Column(name = "maintain_plus_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("e保养+订单")
    private double maintainPlusOrder = 0;

    @Column(name = "maintain_plus_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("e保养+金额")
    private double maintainPlusPrice = 0;

    @Column(name = "tire_plus_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("e轮胎+订单")
    private double tirePlusOrder = 0;

    @Column(name = "tire_plus_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("e轮胎+金额")
    private double tirePlusPrice = 0;

    @Column(name = "qty_month_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("本月累计单数")
    private double qtyMonthOrder = 0;

    @Column(name = "price_month", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本月累计金额")
    private double priceMonth = 0;

    @Column(name = "qty_concurrent_year_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("去年同期单数")
    private double qtyConcurrentYearOrder = 0;

    @Column(name = "price_concurrent_year", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("去年同期保费")
    private double priceConcurrentYear = 0;

    @Column(name = "qty_concurrent_month_order", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("上月同期单数")
    private double qtyConcurrentMonthOrder = 0;

    @Column(name = "price_concurrent_month", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("上月同期保费")
    private double priceConcurrentMonth = 0;

    @Transient
    private Date statisticDateMonth;
    public Date getStatisticDateMonth(){
        return DateUtil.parse(DateUtil.format(this.statisticDate,DateUtil.SHOW_MONTH_FORMAT),DateUtil.SHOW_MONTH_FORMAT);
    }

    @Transient
    private Date statistic;
    public Date getStatistic(){
        return DateUtil.parse(DateUtil.format(this.statisticDate,DateUtil.SHOW_MONTH_FORMAT),DateUtil.SHOW_MONTH_FORMAT);
    }


    @Name
    @Column(name = "statistic_type", length = 120)
    @Comment("统计类型")//salesman:人员,dept:门店
    private String statisticType;
}
